package day1

import junit.framework.TestCase.assertEquals
import kotlin.test.Test
import kotlin.test.assertContains

class FindLongString {
    fun findLongString(str: String): String {
        for (length in str.length downTo 1) {
            Search@ for (inputString in str.windowed(length, 1)) {
                if (inputString.first()==inputString.last()){
                    return inputString
                }
            }
        }
        return ""
    }

    @Test
    fun test1() {
        val str = "babad"
        val result = FindLongString().findLongString(str)
        assertContains(listOf("bab", "aba"), result)
    }

    @Test
    fun test2() {
        val str = "cbbd"
        val result = FindLongString().findLongString(str)
        assertEquals("bb", result)
    }
}